/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package daos;

import beans.AfiliadoSesionBean;
import beans.Bean;
import beans.TipoUsuarioBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 *
 * @author C
 */
public class MSSQLAfiliadoSesionDao extends MSSQLDao implements Dao{

    public MSSQLAfiliadoSesionDao() throws Exception {
        super();
    }   

    @Override
    public Bean make(ResultSet result) throws Exception {
        TipoUsuarioBean t= new TipoUsuarioBean();
        t.setIdTipo(result.getInt("id_tipo")); 
        t.setTipo(result.getString("descripcion"));       
        return t;
    }

    @Override
    public long insert(Bean bean) throws Exception {
        long rs = -1;
         try {
            this.getConnection().setAutoCommit(false);//para mantener la integridad de la base, usar transaccion            
            this.setStatement("insert_sesion_afiliado(?,?)");
            this.getStatement().setLong(1,((AfiliadoSesionBean) bean).getNroAfiliado()); //
            this.getStatement().setInt(2,((AfiliadoSesionBean) bean).getIdObraSocial() );//             
            if (this.getStatement().executeUpdate()==1) {
                this.getConnection().commit();               
            }
             this.setStatement("get_ultimo_registro_sesion()");
             ResultSet    result = this.getStatement().executeQuery();     
              
            result.next();
            rs =result.getLong("id");
            
        } catch (SQLException ex) {
            System.out.println("Error  " + ex);
            this.getConnection().rollback();
            rs = -2;
        } catch (Exception ex2) { 
            this.getConnection().rollback();
            rs = -3;
        }        
        finally {
            this.getConnection().setAutoCommit(true);
          
            this.destroy();
        }
        return rs;    
    }

    @Override
    public void update(Bean bean) throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void delete(Bean bean) throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<Bean> select(Bean bean) throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean valid(Bean bean) throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Bean get(Bean bean) throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public long getSize(Bean bean) throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

  
}
